#!/usr/bin/python3
# -*- coding: utf-8 -*-
#======================================#
# @Author   : duanqizhong
# @time     : 2020-12-26 8:37
# @file     : query_stock_industry
# @Software : PyCharm
#======================================#

import baostock as bs
import pandas as pd

lg=bs.login()

print('login respond error_code:'+lg.error_code)
print("login respond error_msg:"+lg.error_msg)

rs=bs.query_stock_industry()
print("query_stock_industry error_code:"+rs.error_code)
print("query_stock_industry error_msg:"+rs.error_msg)

industry_list=[]
while rs.error_code == '0' and rs.next():
    industry_list.append(rs.get_row_data())

result=pd.DataFrame(industry_list,columns=rs.fields)

result.to_csv('stock_insustry.csv',encoding='gbk',index=False)
print(result)

bs.logout()